<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>登录</title>
    <script src="jquery-1.9.1.min.js"></script>
    <script>
        function mysub(type) {
            var username = jQuery("#username");
            var password = jQuery("#password");
            if (type == 2) {
                // todo:留给你们来实现
                return false;
            }
            // 1.非空效验
            if (username.val().trim() == "") {
                alert("请先输入用户名！");
                username.focus();
                return false;
            }
            if (password.val().trim() == "") {
                alert("请先输入密码！");
                password.focus();
                return false;
            }
            // 2.请求后端，实现登录验证
            jQuery.getJSON("login", {
                "username": username.val(),
                "password": password.val()
            }, function (data) {
                if (data != null && data.succ == 1) {
                    // 登录成功
                    location.href = "myartlist.html";
                } else {
                    // 登录失败
                    alert("登录失败" + data.msg);
                }
            });
        }
    </script>
</head>
<body>
<div style="margin-top: 70px;text-align: center;">
    <h1>登录功能</h1>
    用户名：<input id="username" name="username" type="text">
    <p></p>
    密&nbsp;&nbsp;码：<input id="password" name="password" type="password">
    <p></p>
    <input type="button" onclick="mysub(1)" value=" 提 交 ">
    <input type="button" onclick="mysub(2)" value=" 清 空 ">
</div>
</body>
</html>